###############################################
#Figure 1: Ranked Occupational Risk By Source 
#Author: Raluca L. Pahontu
###############################################

data<- read.csv("ranks.csv") 
data$isco2 <- data$SkillSpec.Rank
data2 <- melt(data, id="isco2")
data2 <- data2[22:105,]
data2$isco2 <- as.factor(data2$isco2)
data2$isco2 <- as.factor(data2$isco2)
fig1 <- ggplot(data2, aes(x=isco2, y=value, group=variable)) 
fig1 + geom_point(aes(shape=variable, colour=isco2), size=2, stroke=1.5) +
  xlab("ISCO-2 Classification") + 
  ylab("Ranked Risk") + theme_bw() +
  geom_segment(x=1, xend=21, y=1, yend=21, col="grey90", linetype="dotted", lwd=.4) +
  theme(panel.grid.minor=element_blank(),
        panel.grid.major = element_blank(),
        panel.border = element_blank(),
        axis.title.y = element_text(margin = margin(t = 0, r = 15, b = 0, l = 0), size=15),
        axis.title.x = element_text(margin = margin(t = 10, r = 20, b = 0, l = 0), size=15),
        axis.ticks.length=unit(0.3,"cm"),
        axis.text = element_text(colour ="black", size=12)) +
  geom_vline(xintercept=seq(1.5,20.5, by=1), linetype="dotted", color="grey60", lwd=.2) +
  geom_hline(yintercept = 0, linetype="dotted", color="grey70", lwd=.2) +
  scale_shape_discrete(solid=FALSE, labels=c("RTI", "Skill Specific", "OUR", "Offshore"), name="Type") + 
  scale_colour_manual(values=c("black", "grey30", "grey40", "grey60", "grey70", "grey60", "grey40", "grey30",
                               "grey40", "grey60", "grey70", "grey60", "grey60", "grey70", "grey80", "grey90",
                               "grey80", "grey70", "grey60", "grey50", "grey40"), guide=FALSE) +
  scale_x_discrete(breaks = c(4,  2, 13,  5,  7, 15, 14,  8,  3, 11,  6,  1, 12, 10, 20, 18,21, 19,  9, 17, 16), 
                   labels = c("12","13","21","22","24","31","32","33","41","42","51","52","71","72","73","74","81","82","83","91","93"))+
  
  scale_y_continuous(breaks=c(0, 21), labels=c("Min", "Max")) +
  coord_cartesian(xlim = c(1, 21), ylim=c(1, 21)) + 
  geom_segment(x=0.4, xend=0.4, y=0, yend=21, col="black") +
  geom_segment(y=0, yend=0, x=0.99, xend=21.01, col="black") 
ggsave("fig1_ranked.pdf")




